package com.colt.contentcenter.sentineldemo;

import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @program: content-center
 * @description: 限流降级class
 * @author: colt
 * @create: 2020-05-26 15:44
 **/
@Slf4j
public class TestControllerBlockHandlerClass {
    /**
     * @Description: 处理限流或者降级
     * @Param:
     * @return:
     * @Author: colt
     * @Date: 2020/5/26
     */
    public static String block(@RequestParam(required = false) Integer userId , BlockException block){
        log.warn("资源被降级或者限流了",block);
        return "资源被降级或者限流了,block";
    }

    public static SentinelClientHttpResponse handleException(HttpRequest request,
                                                             byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
        System.out.println("Oops: " + ex.getClass().getCanonicalName());
        return new SentinelClientHttpResponse("custom block info");
    }

}
